var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasProfile:false,
    canIUseGetUserProfile: false,
     toplogo:'/icon/logo.png',
    topname:'联程汽贸',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that=this;
        var userInfo=wx.getStorageSync('userInfo');
       
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })             
        that.setData({
            platform:app.globalData.platform,    
            userInfo:userInfo,
            width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.domain,
            uploadUrl:app.globalData.uploadUrl,
          })
  },
goMine:function(){
  wx.reLaunch({
    url: '../mine/index',
  })
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getUserProfile(e) {
    let that=this;
    var userInfo=wx.getStorageSync('userInfo');
    var unionId=userInfo.unionid;
    if(unionId){    
     wx.getUserProfile({
      desc: '用于完善会员资料', 
      success: (res) => {
        console.log(res);
        wx.request({
          url: app.globalData.domain+'login/setUserInfo',
          data:{unionId:unionId,nickname:res.userInfo.nickName,avatarUrl:res.userInfo.avatarUrl},
          success:function(e){
            console.log(e);
            if(e.data.return==1){
              var userInfo=wx.getStorageSync('userInfo');
              userInfo.user_nickname=res.userInfo.nickName;
              userInfo.user_head=res.userInfo.avatarUrl;
              //console.log(userInfo)
              wx.setStorageSync('userInfo', userInfo)
             }
             //wx.navigateBack();
             var prevpage=app.globalData.prevpage
             //console.log(prevpage);
             
              wx.reLaunch({
                url:"/pages"+prevpage,
               }) 
               
          }
        })
        this.setData({
          userInfo: res.userInfo,
          hasProfile:false
        })
      }
    })
  }else{
    wx.navigateTo({
      url: 'login',
    })
  }
  }
})